package agenti;

import java.io.IOException;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;

import componenti.comunication.OggettoSalvataggio;

public class AgenteSalvataggio extends Agent {
	private OggettoSalvataggio save;

	@Override
	protected void setup() {
		super.setup();
		Object[] obj = getArguments();
		save = (OggettoSalvataggio) obj[0];
		addBehaviour(new SaveBehaviour());
	}
	
	private class SaveBehaviour extends Behaviour{

		@Override
		public void action() {
			ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
			msg.addReceiver(new AID("AgenteMonitor", AID.ISLOCALNAME));
			try {
				msg.setContentObject(save);
			} catch (IOException e) {
				e.printStackTrace();
			}
			send(msg);

		}


		@Override
		public boolean done() {
			doDelete();
			return false;
		}
		
	}
}
